package com.shell.customer.base.service.impl;

import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.shell.customer.accreditation.vo.CusOptVo;
import com.shell.customer.base.dao.CusOptDao;
import com.shell.customer.base.service.CusOptService;
import com.shell.customer.po.CusOpt;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service("pubCusOptService")
public class CusOptServiceImpl extends PersistentServiceImpl<CusOpt> implements CusOptService {
	@Autowired
	private CusOptDao cusOptDao;

	public CusOpt getLatestOpt(String cusId) {
		return this.cusOptDao.getLatestOpt(cusId);
	}

	public List<CusOptVo> getPreviousOpts(String cusId) {
		List<CusOptVo> optVos = this.cusOptDao.getPreviousOpts(cusId);
		return optVos;
	}

	public CusOpt getLastOptByState(String cusId, String cusState, String bizCode) {
		Example example = new Example(CusOpt.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("bizCode", bizCode);
		criteria.andEqualTo("cusState", cusState);
		criteria.andEqualTo("cusId", cusId);
		List<CusOpt> cusOpts = selectByExample(example);
		if ((null != cusOpts) && (cusOpts.size() > 0)) {
			return (CusOpt) cusOpts.get(0);
		}
		return null;
	}

	public CusOpt getLatestOptReadOnly(String cusId) {
		return this.cusOptDao.getLatestOptReadOnly(cusId);
	}
}
